<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/css/jquery.tooltip.css" />
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.bgiframe.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.dimensions.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.tooltip.js"></script>

<?php $this->layout='main'; ?>

<?php $placebid_form = $this->beginWidget('CActiveForm', array(
		'id'=>'placebid-form',
		'enableClientValidation'=>true,
	//	'enableAjaxValidation'=>true,
		));
?>

<div id="bid-response-contents">
<div id="response-head"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/my-bid-response.gif" alt="" /></div>
<div id="bid-response">

<div id="response-box1">
<div id="box1-contents">

<div id="details-left">
<div id="time-details">
    <div class="box-names">Auction ID</div>
    <div class="grey-box">
    	<?php echo $placebid_form->textField($bidAuction, 'auction_ID', array('disabled'=>'disabled', 'value'=>$auction->auction_ID)); ?>
    </div>
    <div class="box-names">Buyer Name</div>
    <div class="grey-box">
    	<?php 
    		$organizationID = Users::model()->getOrganizationID(Yii::app()->user->userID);
			$organizationName = Organizations::model()->getOrganizationName($organizationID);
    		echo CHtml::textField('buyer', $organizationName, array('disabled'=>'disabled')); 
    	?>
    </div>
    <div class="box-names">Delivery Date</div>
    <div class="grey-box">
    	<?php echo CHtml::textField('delivery_date', date('Y-m-d', strtotime($auction->delivery_due)), array('disabled'=>'disabled')); ?>
    </div>
    <div class="box-names">Delivery Time</div>
    <div class="grey-box">
    	<?php echo CHtml::textField('delivery_time', date('g:i a', strtotime($auction->delivery_due)), array('disabled'=>'disabled')); ?>
    </div>
</div><!-- End Time Details -->

<div id="terms">
<input name="acknowledge" type="checkbox" onchange='clickOnAcknowledge(this)'/>
I Acknowledge that if the product is not
delivered by the time that is posted, that I 
will be subject to the terms and conditions
</div>

</div><!-- End Details Left -->

<div class="details-div">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="details">
  <tr>
    <th>Gallons</th>
    <td>
    <div class="textbox2">
    	<?php echo CHtml::textField('gallons', $auction->gallon, array('disabled'=>'disabled')); ?>
    </div>
    </td>
    
  </tr>
  <tr>
    <th>Fuel Cost<br /><span>Per Gallon</span></th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'fuel_cost_per_gallon', array('onchange'=>'updateLabel(event)')); ?>
    </div></td>
    
  </tr>
  <tr>
    <th>Freight Cost<br /><span>Per Gallon</span></th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'freight_cost_per_gallon', array('onchange'=>'updateLabel(event)'));?>
    </div></td>
    
  </tr>
  <tr>
    <th>Ancillary<br/>Fees</th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'ancillary_fees', array('disabled'=>'disabled'));?>
    </div></td>
    
  </tr>
  <tr>
    <th>Federal<br/>Excise Tax</th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'fed_excise_tax', array('disabled'=>'disabled'));?>
    </div></td>
    
  </tr>
  <tr>
    <th>Federal<br/>Lust</th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'fed_lust', array('disabled'=>'disabled'));?>
    </div></td>
  </tr>
  <tr>
    <th>Federal<br/>Spill Fee</th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'fed_oil_spill_fee', array('disabled'=>'disabled'));?>
    </div></td>
    
  </tr>
  <tr>
    <th>Nc Road<br />Tax</th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'nc_road_tax', array('disabled'=>'disabled'));?>
    </div></td>
    
  </tr>
  <tr>
    <th>Nc<br/>Wholesale</th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'nc_wholesale', array('disabled'=>'disabled'));?>
    </div></td>
    
  </tr>
  <tr>
    <th>Nc<br/>Inspection</th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'nc_inspection', array('disabled'=>'disabled'));?>
    </div></td>
    
  </tr>
  <tr>
    <th>Nc<br />Tare</th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'nc_tare', array('disabled'=>'disabled'));?>
    </div></td>
    
  </tr>
  <tr>
    <th style="height:25px;">&nbsp;</th>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <th class='green'>Delivery Price<br />Per Gallon</th>
    <td><div class="textbox2">
    	<?php echo $placebid_form->textField($bidAuction, 'delivered_price_per_gallon', array('disabled'=>'disabled'));?>
    </div></td>
  </tr>
</table>
</div><!-- End Details Div -->

</div><!-- End Box1 Contents -->
</div><!-- End Response Box1 -->

<div id="response-box2">
<div id="box2-contents">
    <div id="bid-details-head" class="green-heading">Bid Details</div>
		<div id='auction-details' class="search-auction-cont">
		<a id='site-details-button' href="#">
			<img src="<?php echo Yii::app()->request->baseUrl; ?>/images/site-details2.gif" alt="" />
		</a>
			<div id="oo-details">
				    <p><b>Auction ID:</b></p>
				    <p><b>Product:</b></p>
				    <p><b>Gallons Req.:</b></p>
				    <p><b>Inv. Last Read:</b></p>
				    <p><b>Inv. Last Time:</b></p>
				    <p><b>Auction Start Date/Time:</b></p>
				    <p><b>Auction End Date/Time:</b></p>
				    <p><b>Delivery Requested Date/Time:</b></p>
				    <p><b>delivery notes</b></p>
				    <p><b>auction notes</b></p>
			</div><!-- End Open Order Details -->
		</div><!-- End Search Contents -->
    <div class="freight">Freight muist be seperated out.</div>
</div><!-- End Box2 Contnets-->
</div><!-- End Response Box2 -->

<div id="response-box3">
<div id="box3-contents">
<div style="color:#FF0000">
<?php echo $placebid_form->errorSummary($bidAuction); ?>
</div>
</div><!-- End Box3 Contnets-->
</div><!-- End Response Box3 -->

<div id="submit">
	<div style="cursor: pointer" onclick="acknowledge()"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/place-bid.gif" id="place-bid-button" /></div>
</div>

</div><!-- End Bid Response -->
</div><!-- End Bid Response Contents -->

<div id="goodluck">Goodluck</div>
<?php $this->endWidget(); ?>
<script>
function updateLabel(event) {
	var total = parseFloat($("input[name='BidAuctions[fuel_cost_per_gallon]']").val()) 
					+ parseFloat($("input[name='BidAuctions[freight_cost_per_gallon]']").val())
					+ parseFloat($("input[name='BidAuctions[ancillary_fees]']").val())
					+ parseFloat($("input[name='BidAuctions[fed_excise_tax]']").val())
					+ parseFloat($("input[name='BidAuctions[fed_lust]']").val())
					+ parseFloat($("input[name='BidAuctions[fed_oil_spill_fee]']").val())
					+ parseFloat($("input[name='BidAuctions[nc_road_tax]']").val())
					+ parseFloat($("input[name='BidAuctions[nc_wholesale]']").val())
					+ parseFloat($("input[name='BidAuctions[nc_inspection]']").val())
					+ parseFloat($("input[name='BidAuctions[nc_tare]']").val());
	$("input[name='BidAuctions[delivered_price_per_gallon]']").val(total.toFixed(6));
}

/*
* display the new selected auction info 
*/
function displayAuctionDetails()
{
	var auction=<?php echo CJSON::encode($auction) ?>;
	var product=<?php echo CJSON::encode($auction->product) ?>;
	var tank=<?php echo CJSON::encode($auction->tank) ?>;
	var site=<?php echo CJSON::encode($auction->site) ?>;
	var table = document.getElementById('oo-details');
	table.children[0].innerHTML='<b>Auction ID:</b> '+auction.auction_ID;//auction ID
	table.children[1].innerHTML='<b>Product:</b> '+product.product_name;//product name
	table.children[2].innerHTML='<b>Gallons Req.:</b> '+auction.gallon;// gallons
	table.children[3].innerHTML='<b>Inv. Last Read:</b> '+tank.inventory_last_read;//inventory last read
	table.children[4].innerHTML='<b>Inv. Last Time:</b> '+tank.inventory_last_time;//inventory last time
	table.children[5].innerHTML='<b>Auction Start Date/Time:</b> '+auction.auction_start;//auction start time
	table.children[6].innerHTML='<b>Auction End Date/Time:</b> '+auction.auction_end;//auction end time
	table.children[7].innerHTML='<b>Delivery Requested Date/Time:</b> '+auction.delivery_due;//delivery due time
	if(site.notes!=null)
		table.children[8].innerHTML='<b>Delivery notes:</b> '+site.notes;//site delivery notes
	else
		table.children[8].innerHTML='<b>Delivery notes:</b> ';
	if(auction.notes!=null)
		table.children[9].innerHTML='<b>auction notes:</b> '+auction.notes;//auction notes
	else
		table.children[9].innerHTML='<b>auction notes:</b> ';
}

/*
* create a new tooltip,
* display the site details info in the tooltip,
* after changing the selected auction
*/
function displaySiteDetails()
{
	var result='';
	
	var tank=<?php echo CJSON::encode($auction->tank) ?>;
	var site=<?php echo CJSON::encode($auction->site) ?>;
	var rack=<?php echo CJSON::encode($auction->site->rack) ?>;
	var tools=<?php $tools=array();
					foreach($auction->site->sitetoolRelation as $sitetoolRelation)
						$tools[]=$sitetoolRelation->tool;
					echo CJSON::encode($tools);
			 	?>;
	var tankType=<?php echo CJSON::encode($auction->tank->tankType) ?>;
	var tankPosition=<?php echo CJSON::encode($auction->tank->tankPosition) ?>;
	var tankMonitor=<?php $tankMonitor=null;
							if($auction->tank->tank_monitor_ID!=null)
							{
								$tankMoniter=$auction->tank->tankMonitor;
							}
							echo CJSON::encode($tankMonitor) ?>;
	
	result+='<b>SITE ID:</b> '+site.site_ID+'</br>';
	result+='<b>SITE NAME:</b> '+site.site_name+'</br>';
	result+='<b>Address 1:</b> '+site.address1+'</br>';
	result+='<b>Address 2:</b> '+site.address2+'</br>';
	result+='<b>City/State/Zip:</b> '+site.city+', '+site.state+', '+site.zip+'</br>';
	result+='<b>County:</b> '+site.county+'</br>';
	result+='<b>Home Rack:</b> '+rack.city+', '+rack.state+'</br>';
	if(site.gated==1)
	{
		result+='<b>Gated:</b> YES</br>';
		result+='<b>Gated Hours:</b> '+site.gate_opens+'-'+site.gate_closes+'</br>';
	}
	else
	{
		result+='<b>Gated:</b> NO</br>';
	}
	if(site.security_on_premises==1)
	{
		result+='<b>Hour of Operations:</b> '+site.open_time+'-'+site.close_time+'</br>';
	}
	for(var i=0;i<tools.length;i++)
	{
		result+='<b>'+tools[i].tool_name+':</b> YES</br>';
	}
	result+='</br>';
	
	result+='<b>TANK ID:</b> '+tank.tank_ID+'</br>';
	result+='<b>TANK NAME:</b> '+tank.tank_name+'</br>';
	result+='<b>Type of Tank:</b> '+tankType.tank_type_description+'</br>';
	result+='<b>Orientation:</b> '+tankPosition.tank_position_description+'</br>';
	if(tankMonitor!=null)
	{
		result+='<b>Tank Monitor MFG:</b> '+tankMonitor.monitor_MFG+'</br>';
		result+='<b>Tank Monitor Model:</b> '+tankMonitor.monitor_model+'</br>';
	}
	if(tank.remote_fill==1)
	{
		result+='<b>Remote Fill:</b> YES</br>';
	}
	if(tank.overfill_alarm==1)
	{
		result+='<b>Overfill Alarm:</b> YES</br>';
	}
	result+='</br>';
	
	result+='<b>Contact Name:</b> '+site.contact_name+'</br>';
	result+='<b>Phone# of Site:</b> '+site.phone_number_of_site+'</br>';
	result+='<b>After Hour #:</b> '+site.after_hour_number+'</br>';
	
	$("#site-details-button").tooltip({
    	bodyHandler: function() {
	     return result;
	   },
	   showURL: false,
    });
}

displayAuctionDetails()
displaySiteDetails();

/*
* disable the place bid button if not select the acknowledge checkbox
*/
function clickOnAcknowledge(element)
{
	if(element.checked)
		$("#submit").html("<input id='place-bid-button' type='image' src='<?php echo Yii::app()->request->baseUrl; ?>/images/place-bid.gif' />");
	else
		$("#submit").html("<div style='cursor: pointer' onclick='acknowledge()'><img src='<?php echo Yii::app()->request->baseUrl; ?>/images/place-bid.gif' id='place-bid-button' /></div>");
}

function acknowledge() {
	$("#msg-header").show();
	$("#msg-header").html('You must acknowledge the statement to continue.');
}
</script>